// Copyright (c) 2009 Hypirinha contributers
// This program is made available under the terms of the MIT License.
package org.hypirinha.html.codegen;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import org.junit.Test;

import java.util.HashSet;
import java.util.ArrayList;

public class TextTest {

    @Test
    public void shouldGenerateClassThatImplementsContentInterfaces() {
        Text text = new Text();
        ArrayList<String> elements = new ArrayList<String>();
        elements.add("air");
        elements.add("earth");
        elements.add("fire");
        text.addContainingElementTypes(elements);

        GeneratedClass elementInterface = text.createTextClass();

        assertTrue(elementInterface.implementedInterfaces.contains("AirContent"));
        assertTrue(elementInterface.implementedInterfaces.contains("EarthContent"));
        assertTrue(elementInterface.implementedInterfaces.contains("FireContent"));
    }

    @Test
    public void shouldGenerateClassWithSuitableConstructor() {
        Text text = new Text();

        GeneratedClass generatedClass = text.createTextClass();

        Constructor constructor = (Constructor) generatedClass.getMembers().get(1);
        assertEquals("this.content = content;", constructor.getMethodBody());
    }
    
    @Test
    public void shouldGenerateClassWithVisitMethod() {
        Text text = new Text();

        GeneratedClass generatedClass = text.createTextClass();

        ConcreteMethod method = (ConcreteMethod) generatedClass.getMembers().get(2);
        assertEquals("visit", method.getMethodName());
        assertEquals("visitor.text(content);", method.getMethodBody());
    }

}